import ajax  from "../service/ajax.js"

export default{
    namespaced:true,//允许使用命名空间
    state:{
       roleCutObj:{}, //分页对象
       param:{pageNO:1}, //分页查询条件
       roleObj:{}, //查看/修改角色对象
       showRoleAdd:false, //添加角色弹出层是否显示
       showRoleInfo:false,//查看角色弹出层是否显示
       showRoleUpdate:false,//修改角色弹出层是否显示
       updateGradeList:[] //要修改的角色对象绑定的权限ID集合
    },
    mutations:{
        setUpdateGradeList(state,updateGradeList){//设置要修改的用户对象绑定的角色集合
            state.updateGradeList = updateGradeList;
        },
        setRoleCutObj(state,roleCutObj){ //设置分页对象
            state.roleCutObj = roleCutObj;
        },
        setRoleObj(state,roleObj){ //设置查看/修改角色对象
            state.roleObj = roleObj;
            //清空要绑定的权限集合
            state.updateGradeList.length = 0;
            //从角色对象的权限集合中，取出id，添加到state.updateGradeList绑定权限ID集合
            for(var i=0;i<roleObj.gradeList.length;i++){
                state.updateGradeList.push(roleObj.gradeList[i].id);
            }
        },
        setShowRoleAdd(state,isShow){//设置添加角色弹出层是否显示
            state.showRoleAdd = isShow;
        },
        setShowRoleInfo(state,isShow){//设置查看角色弹出层是否显示
            state.showRoleInfo = isShow;
        },
        setShowRoleUpdate(state,isShow){//设置修改角色弹出层是否显示
            state.showRoleUpdate = isShow;
        }
    },
    actions:{
        async cutAllRoleList(context){ //分页查询
           var cutRole = await ajax.getSubmit("/project/role/cutAll",context.state.param);
           context.commit("setRoleCutObj",cutRole);
        }
    }
}